#' Batch Read LI-6800 Induction Excel Files
#'
#' Read all LI-6800 induction Excel files in a directory into a tidy data frame.
#'
#' @param file_dir Character: Path to directory containing induction Excel files
#' @param pattern Character: Regular expression to match Excel files (default: "\\.xlsx$")
#' @param recursive Logical: Whether to read files recursively (default: FALSE)
#' @param verbose Logical: Whether to print progress messages (default: TRUE)
#' @return Tidy data frame with combined induction data (one row per time point per sample)
#' @export
#' 
read_all_induction = function(
  file_dir,
  pattern = "\\.xlsx$",
  recursive = FALSE,
  verbose = TRUE
) {

  # list all data files in a folder
  file_paths = list.files(
    path = file_dir,
    pattern = pattern,
    full.names = TRUE,
    recursive = recursive
  )

  if (length(file_paths) == 0) {
    stop(sprintf("No files matching pattern '%s' found in '%s'", pattern, file_dir))
  }

  # read all the data in a folder
  all_data = lapply(file_paths, function(file) {
    if (verbose) {
      message(sprintf("Reading file: %s", basename(file)))
    }
    # use read induction
    df = read_induction(file)
    # add a SOURCE colums to distinguish the data source(default file name)
    df$SOURCE = tools::file_path_sans_ext(basename(file))
    df
  })

  # combine all the data
  combined_data = do.call(rbind, all_data)
  rownames(combined_data) = NULL  
  return(combined_data)
}

